package com.shengde.jinwawaforleader;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.widget.Toast;

import com.shengde.jinwawaforleader.bean.User;
import com.shengde.jinwawaforleader.model.myJob.instance_message.DemoHelper;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.videogo.constant.Config;
import com.videogo.openapi.EZOpenSDK;

import org.xutils.x;
import im.fir.sdk.FIR;


/**
 * Created by Chason on 2016/8/26.
 */

public class HomeApplication extends MultiDexApplication {
	/***
	 * 存放的activity
	 ***/
	public static Toast toast;
	public static HomeApplication instance;
	public static Handler mHander = new Handler();
	public static String APP_KEY = "2f0e7e42160d4b9eb36f2a28c9efc2d5"; // 2015/10/29
	public static Context applicationContext;
	public String version;  //		// 获取手机android版本

	@Override
	public void onCreate() {
		super.onCreate();
		MultiDex.install(this);

		instance = this;
		applicationContext = this;
		getTelephoneVersion();
		initXutis();
		init_ys();
		initHuanXin();
		initUmengShare();
		initBugCollect();

	}

	/**
	 * 初始化Bug收集
	 */
	private void initBugCollect() {
		FIR.init(this);
	}

	/**
	 * 获取手机android版本
	 */
	private void getTelephoneVersion() {
		version = Build.VERSION.RELEASE;
		User.setMyCode(applicationContext,version);
	}

	/**
	 * 初始化友盟分享
	 */
	private void initUmengShare() {
		UMShareAPI.get(this);
		PlatformConfig.setWeixin("wx422af8393eb35f54", "b68635119001613fa3ef38255208ad94");
		PlatformConfig.setQQZone("1105619093", "pICHtpeysEkNKwG0");
	}

	/**
	 * 初始化 环信 即时通讯
	 */
	private void initHuanXin() {

		//init demo helper
		DemoHelper.getInstance().init(applicationContext);
		//red packet code : 初始化红包上下文，开启日志输出开关
	/*	RedPacket.getInstance().initContext(applicationContext);
		RedPacket.getInstance().setDebugMode(true);*/

	}

	/**
	 * 初始化xUtils3
	 */
	private void initXutis() {
		x.Ext.init(this);
		x.Ext.setDebug(true);
	}

	/**
	 * 初始化萤石云 视频监控sdk 设置APPKEY
	 *
	 * @return
	 */
	private boolean init_ys() {
		Config.LOGGING = true;
		EZOpenSDK.initLib(this, APP_KEY, "");

		Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread thread, Throwable throwable) {
				throwable.printStackTrace();
			}
		});
		return EZOpenSDK.initLib(this, APP_KEY, "");
	}

	public static HomeApplication getInstance() {
		return instance;
	}

	/**
	 * 提示内容显示Toast
	 *
	 * @param msg 消息内容
	 */
	public static synchronized void showToastShort(String msg) {
		if (toast != null) {
			toast.cancel();
		}
		toast = Toast.makeText(instance, msg, Toast.LENGTH_SHORT);
		toast.show();
	}

	/**
	 * 提示内容显示Toast
	 *
	 * @param msg 消息内容
	 */
	public static synchronized void showToastLong(String msg) {
		if (toast != null) {
			toast.cancel();
		}
		toast = Toast.makeText(instance, msg, Toast.LENGTH_LONG);
		toast.show();
	}

	@Override
	protected void attachBaseContext(Context base) {
		super.attachBaseContext(base);
		MultiDex.install(this);
	}


}